package com.md.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public class MapUtils {
	
	/**
	 * 拼接配置参数
	 * @param map
	 * @return
	 */
	public static String MapToString(Map<String,Object> map){
		StringBuffer sb =new StringBuffer();
		for(String key:map.keySet()){
			//支付宝官方
			String zfbGfKey="app_id,sign_type,ali_publicKey,app_pubKey,app_priKey";
			//微信官方
			String wxGfKey="fmMchntId,fmMerKey,wxAppid,wxSercet,app_priKey";
			//富民
			String fuMingKey="appid,appSecret,key,cert_path";
			if(zfbGfKey.contains(key)||wxGfKey.contains(key)||fuMingKey.contains(key)){
				sb.append(key).append("=^=").append(map.get(key)).append("&^&");				
			}
		}
	    String str = sb.substring(0, sb.length()-3).toString();
	    return str;
	}
	
	/**
	 * 将字符串转为map
	 * 字符串格式：key=^=value&^&key=^=value&^&...
	 * @param str
	 * @return
	 */
	public static Map<String,String> strToMap(String str){
		Map<String,String> map=new HashMap<String, String>();
		if(!StringUtils.isEmpty(str)){
			String [] str1=str.split("&\\^&");
			for(String str2:str1){
				String [] str3=str2.split("=\\^=");
				map.put(str3[0], str3[1]);
			}
		}
		return map;
	}
}
